package com.tanhua.server.controller;

import com.tanhua.server.service.SoundService;
import com.tanhua.server.vo.SoundVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RequestMapping("/peachblossom")
@RestController
public class SoundController {

    @Autowired
    private SoundService soundService;


    /**
     * 发送语音
     * @param file 语音文件
     * @param
     * @return
     */
    @PostMapping
    public ResponseEntity<Void> saveSound(@RequestParam("soundFile") MultipartFile file){
        try {
            Boolean bool = soundService.saveSound(file);
            if(bool){
                return ResponseEntity.ok(null);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }


    /**
     * 接受语音
     * @return
     */
    @GetMapping
    public ResponseEntity<SoundVo> querySound(){
        try {
            SoundVo soundVo = soundService.querySound();
            return ResponseEntity.ok(soundVo);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
